# coding: utf-8

# 配置文件类,处理配置相关功能

import os
import sys
import glob
import configparser


class Config(object):
    def __init__(self, cfg_file):
        self.cfg_file = cfg_file

    def parse(self):
        # 读取配置文件
        cf = configparser.ConfigParser()
        try:
            print("解析文件：" + self.cfg_file)
            cf.read(self.cfg_file, encoding='utf-8')

            cfg_list = {
                'debug': cf.getboolean("Main", "debug"),
                'zip_path': cf.get("Main", "zip_path"),
                'export_type': cf.get("Main", "export_type"),
                'send_to_email': cf.getboolean("Main", "send_to_email"),
                'send_list': cf.get("Main", "send_list"),
                'send_title': cf.get("Main", "send_title"),
                'desc': cf.get("Main", "desc"),
                'parallel': cf.getboolean("Main", "parallel"),
                'dynamic_table': cf.getboolean("Main", "dynamic_table"),
                'smtp_server': cf.get("sendmail", "smtp_server"),
                'port': cf.getint("sendmail", "port"),
                'user': cf.get("sendmail", "user"),
                'passwd': cf.get("sendmail", "passwd"),
                'ssl': cf.getboolean("sendmail", "ssl"),
                'sender': cf.get("sendmail", "sender"),
            }

            # 解析参数
            return cfg_list
        except Exception as e:
            print(e)


if __name__ == '__main__':
    config = Config("F:\\export\\task\\风控日报定时任务申请-20210112101\\config.ini").parse()
    print(config.get('debug'))

